package com.max.mil.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.max.mil.common.util.DataPage;
import com.max.mil.model.GraContent;
import com.max.mil.service.GraContentServiceImpl;
import com.max.mil.share.GraContentService;

@Controller
public class GraphicsController
{
	GraContentService graContentService = new GraContentServiceImpl();
	
	@RequestMapping("/index")
	public String index(Integer pageNo, Integer pageSize, Model model) throws Exception 
	{
		if(pageNo == null || pageNo<1) pageNo = 1;
		if(pageSize == null || pageSize<1) pageSize = 20;
		System.out.println("pageNo="+pageNo+",pageSize="+pageSize);
		
		DataPage<GraContent> dp = graContentService.get(pageNo, pageSize);
		model.addAttribute("dp", dp);
		
		return "index";
	}
	
	@RequestMapping("/details")
	public String details(int id, Model model) throws Exception 
	{
		GraContent graContent = graContentService.get(id);
		List<GraContent> mayLove = graContentService.getRand(4);
		List<GraContent> recommd = graContentService.getRand(4);
		List<GraContent> related = graContentService.getRand(10);
		List<GraContent> hotoday = graContentService.getRand(10);
		
		model.addAttribute("graContent", graContent);
		model.addAttribute("mayLove", mayLove);
		model.addAttribute("recommd", recommd);
		model.addAttribute("related", related);
		model.addAttribute("hotoday", hotoday);
		
		return "details";
	}
}
